package utils

import (
	"../model/dto"
	"encoding/json"
	"log"
	"net/http"
)

/**
 * 返回数据
 */
func WriteResult(writer http.ResponseWriter, code int, data interface{}, msg string) {

	writer.Header().Set("Content-Type", "application/json")

	user := dto.UserDto{
		Code: code,
		Data: data,
		Msg:  msg,
	}

	result, err := json.Marshal(user)
	if err != nil {
		log.Println(err.Error())
	}

	_, err = writer.Write(result)
	if err != nil {
		log.Fatal(err.Error())
	}
}
